package org.xlp.validate.code;

import java.util.Random;

/**
 * Description: 图片验证码生成器
 * <br/>date: 2024/11/18 18:57
 *
 * @version 1.0
 * @author: xlp
 */
public class ValidateCode extends AbstractValidateCode{
    /**
     * 图片验证码中的字符来源数组
     */
    private static final char[] CODE_SEQUENCE = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
            'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
            'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

    public ValidateCode() {
        super();
    }

    public ValidateCode(int width, int height) {
       super(width, height);
    }

    public ValidateCode(int width, int height, int codeCount, int lineCount) {
        super(width, height, codeCount, lineCount);
    }

    public ValidateCode(int width, int height, int lineCount) {
        super(width, height, lineCount);
    }

    @Override
    protected String randomCode() {
        StringBuilder randomCode = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < getCodeCount(); i++) {
            randomCode.append(String.valueOf(CODE_SEQUENCE[random.nextInt(CODE_SEQUENCE.length)]));
        }
        return randomCode.toString();
    }
}
